#!/bin/bash

THIS_DIR=$(
    cd $(dirname "$0")
    pwd
)

mkdir -p $THIS_DIR/ndk-build-toolchain

export NDK_TOOLCHAIN_DIR=$THIS_DIR/ndk-build-toolchain

mkdir -p $NDK_TOOLCHAIN_DIR && cd $NDK_TOOLCHAIN_DIR && git init

if [[ ! -d "$NDK_TOOLCHAIN_DIR/arm" ]]; then
    $NDK/build/tools/make-standalone-toolchain.sh --arch=arm --toolchain=arm-linux-android-clang3.6 --platform=android-22 --install-dir=$NDK_TOOLCHAIN_DIR/arm --stl=libc++
fi

if [[ ! -d "$NDK_TOOLCHAIN_DIR/arm64" ]]; then
    $NDK/build/tools/make-standalone-toolchain.sh --arch=arm64 --toolchain=aarch64-linux-android-clang3.6 --platform=android-22 --install-dir=$NDK_TOOLCHAIN_DIR/arm64 --stl=libc++
fi

if [[ ! -d "$NDK_TOOLCHAIN_DIR/x86" ]]; then
    $NDK/build/tools/make-standalone-toolchain.sh --arch=x86 --platform=android-22 --install-dir=$NDK_TOOLCHAIN_DIR/x86 --stl=libc++
fi

if [[ ! -d "$NDK_TOOLCHAIN_DIR/x86_64" ]]; then
    $NDK/build/tools/make-standalone-toolchain.sh --arch=x86_64 --toolchain=x86_64-linux-android-clang3.6 --platform=android-22 --install-dir=$NDK_TOOLCHAIN_DIR/x86_64 --stl=libc++
fi

# if [[ "$NDK_STANDALONE_TOOLCHAIN" == "" ]]; then

#   if [[ "$NDK" == "" ]]; then
#     echo "You should set the NDK variable to your ndk-dir!"
#     exit
#   fi

#   export NDK_STANDALONE_TOOLCHAIN=$NDK/ndk-build-toolchain
#   rm -rf $NDK_STANDALONE_TOOLCHAIN
#   $NDK/build/tools/make-standalone-toolchain.sh  --platform=android-22 --install-dir=$NDK_STANDALONE_TOOLCHAIN --stl=libc++

# fi

# echo "NDK_STANDALONE_TOOLCHAIN=$NDK_STANDALONE_TOOLCHAIN"
